package com.example.pathprotectsystem.controller;

import com.example.pathprotectsystem.pojo.*;
import com.example.pathprotectsystem.service.BindService;
import com.example.pathprotectsystem.service.RecordService;
import com.example.pathprotectsystem.service.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ResultController {
    @Autowired
    private ResultService resultService;
    @Autowired
    private BindService bindService;

    @PostMapping("/usertasklist")
    public Result<PageBean<BindModel>> usertasklist(@RequestBody AskList askList){
        PageBean<BindModel> p = resultService.usertasklist(askList);
        return Result.success(p);
    }
    @PostMapping("/addf1")
    public Result addf1(@RequestBody SheetModel sheetModel){
        resultService.addf1(sheetModel);
        bindService.taskupdatestatus(sheetModel.getId());
        return Result.success();
    }
    @PostMapping("/addf2")
    public Result addf2(@RequestBody SheetModel sheetModel){
        resultService.addf2(sheetModel);
        bindService.taskupdatestatus(sheetModel.getId());
        return Result.success();
    }
    @PostMapping("/addf3")
    public Result addf3(@RequestBody SheetModel sheetModel){
        System.out.println(sheetModel);
        resultService.addf3(sheetModel);
        bindService.taskupdatestatus(sheetModel.getId());
        return Result.success();
    }
    @PostMapping("/addf4")     
    public Result addf4(@RequestBody SheetModel sheetModel){
        System.out.println(sheetModel);
        resultService.addf4(sheetModel);
        bindService.taskupdatestatus(sheetModel.getId());
        return Result.success();
    }
    @PutMapping("/finaltask")
    public Result finaltask(int id){
        String s = bindService.getstatus(id);
        if(s.equals("未填写")){
            return Result.error("没有填写记录表，此任务无法完成提交");
        }
        bindService.taskfinalstatus(id);
        return  Result.success();
    }
}
